package com.alibaba.citrus.cr.sales.plan.facade.service.statistics;

import com.alibaba.citrus.cr.common.annotation.FacadeInvoker;
import com.alibaba.citrus.cr.sales.plan.functions.ability.model.DeletePlanCustomerAbilityRequest;
import com.alibaba.citrus.cr.sales.plan.functions.salesplan.SalesPlanCustomerStatEntity;
import com.alibaba.citrus.cr.sales.plan.functions.salesplan.SalesPlanStatAbility;
import com.alibaba.citrus.cr.sales.plan.sdo.SalesPlanStatCustomerSDO;
import com.alibaba.citrus.cr.sales.plan.api.statistics.SalesPlanCustomerStatWriteService;
import com.alibaba.citrus.cr.sales.plan.dto.api.request.DeleteSalesPlanCustomerStatRequest;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author yuhailin
 * @description:
 * @date 2021-09-27 10:36
 */
@Component
public class SalesPlanCustomerStatWriteServiceImpl implements SalesPlanCustomerStatWriteService {
    @Resource
    SalesPlanStatAbility salesPlanStatAbility;

    @FacadeInvoker
    @Override
    public Result<String> createPlanCustomer(SalesPlanStatCustomerSDO salesPlanCustomerStatSDO) {
        // 构造实体
        SalesPlanCustomerStatEntity salesPlanCustomerEntity = SalesPlanCustomerStatEntity.of(salesPlanCustomerStatSDO);
        String lastInsertId = salesPlanCustomerEntity.planCustomerSave();
        return Result.success(lastInsertId);
    }

    @FacadeInvoker
    @Override
    public Result<Boolean> deletePlanCustomer(DeleteSalesPlanCustomerStatRequest deleteSalesPlanCustomerStatRequest) {
        DeletePlanCustomerAbilityRequest deletePlanCustomerAbilityRequest = new DeletePlanCustomerAbilityRequest();
        deletePlanCustomerAbilityRequest.setId(deleteSalesPlanCustomerStatRequest.getId().toString());
        return Result.success(salesPlanStatAbility.deletePlanCustomer(deletePlanCustomerAbilityRequest));
    }
}
